package org.luxor.commons.jdbc.config;

import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;

import java.util.HashMap;
import java.util.Map;

/**
 * 初始化mybatis-plus配置，关闭banner
 * @author Mr.yan @date 2019/11/20
 */
public class MybatisPlusApplicationContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
    private static final String MYBATISPLUS_BOOTSTRAP_PROPERTY_SOURCE_NAME = "mybatisPlus";

    @Override
    public void initialize(ConfigurableApplicationContext context) {
        Map<String, Object> source = new HashMap<>(2);
        source.put("mybatis-plus.global-config.banner", false);
        ConfigurableEnvironment environment = context.getEnvironment();
        environment.getPropertySources().addFirst(new MapPropertySource(MYBATISPLUS_BOOTSTRAP_PROPERTY_SOURCE_NAME, source));
    }
}
